
#ifndef _AIRC_H
#define _AIRC_H

/* Purple dependencies */
#include <plugin.h>
#include <glib.h>

#include <internal.h>
#include <circbuffer.h>
#include <debug.h>
#include <ft.h>
#include <roomlist.h>
#include <sslconn.h>
#include <version.h>
#include <accountopt.h>
#include <blist.h>

#define IRC_DEFAULT_NETWORK "Acuity Services"
#define IRC_DEFAULT_SERVERS "irc.acuityservices.org:6667, valor.acuityservices.org:+6697"
#define IRC_DEFAULT_PORT 6667
#define IRC_DEFAULT_CHARSET "UTF-8"
#define IRC_DEFAULT_AUTODETECT FALSE
#define IRC_DEFAULT_QUIT "Leaving."
#define IRC_DEFAULT_PART "Leaving."
#define IRC_DEFAULT_GECOS "Purple"
#define IRC_INITIAL_BUFSIZE 1024
#define AIRC_CBSTATUSMODE_BASE 0x0040
#define PING_TIMEOUT 60

#define IRCDATA(conn) (IRC_conn*)(conn ->proto_data);

typedef struct _airc_conn IRC_conn;
typedef struct _airc_buddy IRC_buddy;
typedef struct _airc_splithost IRC_splithost;

void airc_register_usercmds(void);
void airc_unregister_usercmds(void);
void airc_parse_msg(IRC_conn *irc, char *input);
char *airc_parse_mirc_to_html(char *input);
char *airc_nick_skip_mode(IRC_conn *irc, char *who);
gboolean airc_is_channel(IRC_conn *irc, char *target);
IRC_splithost *airc_split_host(IRC_conn *irc, char *userhost);
void free_splithost(IRC_splithost *userhost);
int airc_get_flag_from_statuschar(IRC_conn *irc, char statuschar);
int airc_get_mode_class(IRC_conn *irc, char mode);
int airc_get_flag_from_mode(IRC_conn *irc, char mode);
int irc_send(IRC_conn *irc, const char *format, ...);
int airc_send(IRC_conn *irc, const char *buf, int len);
int airc_parse_rawcmd(IRC_conn *irc, const char *who, const char *raw);

extern PurplePlugin *airc_plugin;

struct _airc_conn {
    PurpleAccount *account;
    GHashTable *buddies;
    PurpleRoomlist *roomlist;
    char *listCmd;
    time_t lastping;
    guint timer;
    PurpleSslConnection *gsc;
    int fd;
    PurpleCircBuffer *outbuf;
    char *inbuf;
    int inbuflen;
    int inbufused;
    guint writeh;
    
    char *nick;
    struct _airc_features {
        char *statusmsg;
        char *prefix;
        char *chantypes;
        char *network;
        char **chanmodes;
        gboolean watch;
    } features;
    struct _airc_requests {
        gboolean preconnected;
        gboolean connected;
        enum {
            MOTD_SUPPRESS = 0,
            MOTD_FETCH
        } motd;
        enum {
            WHO_SUPPRESS = 0,
            WHO_FETCH
        } who;
        enum {
            WHOIS_SUPPRESS = 0,
            WHOIS_FETCH,
            WHOWAS_FETCH
        } whois;
    } requests;
    struct _airc_dialogs {
        PurpleNotifyUserInfo *whois;
    } dialogs;
};

struct _airc_buddy {
    char *name;
    gboolean online;
    gboolean flag;
    gboolean new_online_status;
    int ref;
};

struct _airc_splithost {
    char *nick;
    char *ident;
    char *host;
};



#endif /* _AIRC_H */